package com.deve.pig.service.merchant.impl;

import com.deve.pig.common.BusinessData;
import com.deve.pig.mapper.MerchantCategoryMapper;
import com.deve.pig.model.MerchantCategory;
import com.deve.pig.model.MerchantCategoryExample.Criteria;
import com.deve.pig.model.MerchantCategoryExample;
import com.deve.pig.service.merchant.IMerchantCategoryService;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import my.utils.Pagination;
import org.springframework.stereotype.Service;

@Service("merchantCategoryService")
public class MerchantCategoryServiceImpl extends BusinessData implements IMerchantCategoryService {
    @Resource
    private MerchantCategoryMapper merchantCategoryMapper;

    @Override
    public int add(MerchantCategory entity) {
        return merchantCategoryMapper.insert(entity);
    }

    @Override
    public int delete(MerchantCategoryExample example) {
        return merchantCategoryMapper.deleteByExample(example);
    }

    @Override
    public int delete(int id) {
        return merchantCategoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(MerchantCategory entity) {
        return merchantCategoryMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public Pagination findPagination(Map<String, Object> queryMap, int currentPage, int pageSize) {
        MerchantCategoryExample merchantCategoryExample = new MerchantCategoryExample();
        //Criteria criteria = merchantCategoryExample.createCriteria();
        // 设置搜索条件参数
        //if(queryMap != null){
            //if(queryMap.containsKey("username")) {
                //criteria.andUserNameLike("%"+(String)queryMap.get("username")+"%");
                //}
                //if(queryMap.containsKey("email")){
                    //criteria.andEmailLike((String)queryMap.get("email"));
                    //}
                    //}
                    // 设置分页参数
                    merchantCategoryExample.setPageSize(pageSize);
                    merchantCategoryExample.setStartIndex((currentPage-1)*pageSize);
                    List<MerchantCategory> items = merchantCategoryMapper.selectByExample(merchantCategoryExample);
                    int totalCount = (int)merchantCategoryMapper.countByExample(merchantCategoryExample);
                    return new Pagination(pageSize, currentPage, totalCount, items);
                }

    @Override
    public MerchantCategory findById(int id) {
        return merchantCategoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MerchantCategory> findAll() {
        return merchantCategoryMapper.selectByExample(null);
    }

    @Override
    public List<MerchantCategory> findByCriteria(MerchantCategoryExample criteria) {
        return merchantCategoryMapper.selectByExample(criteria);
    }

    @Override
    @SuppressWarnings("unchecked")
    public LinkedHashMap<String, List> getExportData() {
        LinkedHashMap<String, List> map = new LinkedHashMap<String, List>();
        map.put("SheetName_1", findAll());
        map.put("SheetName_2", findAll());
        map.put("SheetName_3", findAll());
        map.put("SheetName_N", findAll());
        return map;
    }

    @Override
    public int countByExample(MerchantCategoryExample example) {
        return merchantCategoryMapper.countByExample(example);
    }
}